"""
创建文件:data.txt 一共1w行,每行存放一个1-100间的随机整数
找出文件中数字出现最多的十个数字
"""
import random

with open("data.txt", 'a+') as file_obj:
    for i in range(10000):
        num = random.randint(1, 100)
        file_obj.write(f"{num}\n")

    file_obj.seek(0)

    list_num = []
    for i in range(101):
        list_num.append(0)

    while True:
        line = file_obj.readline()
        if not line:
            break
        elif line[-1] == '\n':
            print(line[:-1:], end="")
            list_num[int(line[:-1:])] += 1
        else:
            print(line, end="")
            list_num[int(line)] += 1

print()
print(list_num)

set_max = set()
for i in range(10):
    max_i = 0
    for j in range(100):
        if list_num[max_i] < list_num[j] and j not in set_max:
            max_i = j
    set_max.add(max_i)
print(set_max)


# count也可以